#pragma once

#include <sstream>
#include <fstream>

#define GRAPH_EXTENSION ".xgmml"

#define PRINT_GRAPH(FILENAME, GRAPH)                              \
  do                                                              \
    {                                                             \
    std::ostringstream filename;                                  \
    filename << FILENAME << GRAPH_EXTENSION << ends;              \
    GRAPH.GetBoostGraph ()[graph_bundle].name = filename.str ();  \
    std::ofstream (filename.str ().c_str ()) << GRAPH;            \
    } while (false);

#ifdef _DEBUG
#define DEBUG_PRINT_GRAPH(FILENAME, GRAPH) PRINT_GRAPH(FILENAME, GRAPH)
#else
#define DEBUG_PRINT_GRAPH(FILENAME, GRAPH)
#endif


#define PRINT_VECTOR(FILENAME, VECTOR)                            \
  do                                                              \
    {                                                             \
    const uint width = 4;                                         \
                                                                  \
    std::ostringstream filename;                                  \
    filename << FILENAME << ".txt" << ends;                       \
    std::ofstream file (filename.str ().c_str ());                \
                                                                  \
    for (uint i=0; i<VECTOR.size(); i++)                          \
      {                                                           \
      file                                                        \
        << "(" << setw (width) << i                               \
        << ", " << setw (width) << VECTOR[i]                      \
        << ")" << endl;                                           \
      }                                                           \
                                                                  \
    file.close ();                                                \
                                                                  \
    } while (false);

#define DEBUG_X(MSG,TAG)                                      \
  do                                                          \
    {                                                         \
    std::ostringstream msg;                                   \
    msg << MSG << std::endl;                                  \
    std::cout << TAG << " " << __FILE__ << ":" << __LINE__    \
      << " " << msg.str ();                                   \
    } while (false);

#ifndef _NO_DEBUG_LOG
#define DEBUG_LOG(MSG) DEBUG_X(MSG,"[LOG]")
#else
#define DEBUG_LOG(MSG)
#endif

#ifndef _NO_DEBUG_WRN
#define DEBUG_WRN(MSG) DEBUG_X(MSG,"[WRN]")
#else
#define DEBUG_WRN(MSG)
#endif

#ifndef _NO_DEBUG_ERR
#define DEBUG_ERR(MSG) DEBUG_X(MSG,"[ERR]")
#else
#define DEBUG_ERR(MSG)
#endif
